package p0;

public class Leetcode_12 {

    public String intToRoman(int num) {
        if (num < 1 || num > 4000) {
            return null;
        }
        int[] nums = new int[]{1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
        String[] strings = new String[]{"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};
        int index = 0;
        StringBuilder result = new StringBuilder();
        while (index <= 12) {
            while (num >= nums[index]) {
                result.append(strings[index]);
                num -= nums[index];
            }
            index++;
        }
        return result.toString();
    }

    public static void main(String[] args) {
        Leetcode_12 l = new Leetcode_12();
        System.out.println(l.intToRoman(4));
    }
}
